<?php
	
class Db{				
		public $sqldb;
		
		public function __construct($loader){
			$config = $loader -> config("database");
			$dsn = 'mysql:dbname='.$config["name"].';host='.$config["host"];
			$user = $config['username'];
			$password = $config['password'];
			try {
				$this->sqldb = new PDO($dsn, $user, $password);
			} catch (PDOException $e) {
				echo 'Connection failed: ' . $e->getMessage();
			}
		}
				
		public function query($sql, $bind = array(), $fetch = FALSE, $bindType = TRUE){
			$q=$this->sqldb->prepare($sql);
			if (empty($bindType) || $bindType === FALSE)
				$q->execute($bind);
			else{	
				$values = array();				
				foreach($bind as $value) {
					$values[]=$value;
				}
				$q->execute($values);
			}
			if($fetch === TRUE) return $q;
			else{
				if ($q === FALSE) return FALSE;
				else{
					return $q->fetchAll();
				}
			}
		}
		
		public function index(){
			echo 'Hello DB.php index<br />';
		}
		
		public function __destruct(){
			$sqldb=null;
		}
}

//áésaáéáéáslgéáéááééáá